package com.example.arithmeticleetcode.leetcode.nov;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-11-24 09:50
 **/
public class Demo16 {

    public static void main(String[] args) {

    }

    public int getDecimalValue(ListNode head) {
        StringBuilder stringBuilder = new StringBuilder();
        while (head != null) {
            stringBuilder.append(head.val);
            head = head.next;
        }
        int sum = 0;
        String str = stringBuilder.toString();
        int count = 0;
        for (int i = 0, len = str.length(); i < len; i++) {
            int value = str.charAt(i) - 48;
            sum += (value * Math.pow(2, count++));
        }
        return sum;
    }
}
